package com.jxd.project.travel.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * @ClassName FileUploadConfig
 * @Description TODO
 * @Author 邢子剑
 * @Date 2025/10/7 上午10:05
 * @Version 1.0
 */
@Configuration
public class FileUploadConfig implements WebMvcConfigurer {
    // 从配置文件读取上传路径和访问路径
    @Value("${file.upload-path}")
    private String uploadPath;
    @Value("${file.access-path}")
    private String accessPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String realPath = System.getProperty("user.dir") + File.separator + uploadPath;
        registry.addResourceHandler(accessPath)
                .addResourceLocations("file:" + realPath); // "file:"表示本地文件系统
    }
}